//
//  OrderManager.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/5/11.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "OrderManager.h"

@implementation OrderManager

///取消订单
+(void)cancelOrderWithOrderNo:(NSString *)orderNo withSuccessBlock:(void (^)(void))successBlock{
    [OrderManager showCustomAlertTitle:@"提示" message:@"确定要取消订单吗？" confirmBlock:^{
        [NetWorkingOrder cancelOrderWithOrderNo:orderNo withSuccessBlock:^(id  _Nonnull responseObj) {
            [[XNProgressHUD shared] showSuccessWithTitle:@"订单已取消！"];
            successBlock();
        }];
    }];
}

///去支付
+(void)payWithOrderNo:(NSString *)orderNo withSuccessBlock:(void (^)(void))successBlock withPayBlock:(void (^)(id payResponseDict))payBlock{
    [NetWorkingOrder orderPayWithOrderNo:orderNo withSuccessBlock:^(id  _Nonnull responseObj) {
        id data = responseObj[@"data"];
        if ([data isKindOfClass:[NSDictionary class]]) {
            NSDictionary *dict = (NSDictionary *)data;
            if ([dict.allKeys containsObject:@"noncestr"]) {
                //拉起支付
                payBlock(dict);
            }else{
                [[XNProgressHUD shared] showSuccessWithTitle:@"支付成功！"];
                successBlock();
            }
        }else{
            [[XNProgressHUD shared] showSuccessWithTitle:@"支付成功！"];
            successBlock();
        }
    }];
}
///删除订单
+(void)deleteOrderWithOrderNo:(NSString *)orderNo withSuccessBlock:(void (^)(void))successBlock{
    [OrderManager showCustomAlertTitle:@"提示" message:@"要删除此订单吗？此操作不可恢复!" confirmBlock:^{
        [NetWorkingOrder deleteOrderWithOrderNo:orderNo withSuccessBlock:^(id  _Nonnull responseObj) {
            [[XNProgressHUD shared] showSuccessWithTitle:@"订单已删除！"];
            successBlock();
        }];
    }];
}

///确认完成
+(void)confrimDoneWithID:(NSString *)itemID withSuccessBlock:(void (^)(void))successBlock{
    [NetWorkingOrder confirmDoneOrder:itemID withSuccessBlock:^(id  _Nonnull responseObj) {
        [[XNProgressHUD shared] showSuccessWithTitle:@"订单已完成！"];
        successBlock();
    }];
}
//确认收货
+(void)confirmTheGoodsWithOrderNo:(NSString *)orderNo withSuccessBlock:(void (^)(void))successBlock{
    [OrderManager showCustomAlertTitle:@"温馨提示" message:@"确认收货吗？" confirmBlock:^{
        [NetWorkingOrder OrderReceiveConfirmWithOrderNo:orderNo withSuccessBlock:^(id  _Nonnull responseObj) {
            [[XNProgressHUD shared] showSuccessWithTitle:@"确认收货成功!"];
            successBlock();
        }];
    }];
}










//自定义提示
+(void)showCustomAlertTitle:(NSString *)title message:(NSString *)message confirmBlock:(void(^)(void))confirmBlock{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        confirmBlock();
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
    }];
    [alert addAction:confirmAction];
    [alert addAction:cancelAction];
    [[Configuration getCurrentVC] presentViewController:alert animated:YES completion:nil];
}


@end
